<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@  taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16"
          href="images/favicon.png">
    <title>Ela - Bootstrap Admin Dashboard Template</title>

    <link href="${pageContext.request.contextPath}/css/lib/sweetalert/sweetalert.css" rel="stylesheet">
    <!-- Bootstrap Core CSS -->
    <link href="${pageContext.request.contextPath}/css/lib/bootstrap/bootstrap.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="${pageContext.request.contextPath}/css/helper.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet">
</head>

<body class="fix-header fix-sidebar">
<!-- Preloader - style you can find in spinners.css -->
<div class="preloader">
    <svg class="circular" viewBox="25 25 50 50">
        <circle class="path" cx="50" cy="50" r="20" fill="none"
                stroke-width="2" stroke-miterlimit="10"/>
    </svg>
</div>
<!-- Main wrapper  -->
<div id="main-wrapper">
    <!-- header header  -->
    <%@ include file="../common/header.jsp" %>
    <!-- End header header -->
    <!-- Left Sidebar  -->
    <%@ include file="../common/nav.jsp" %>
    <!-- End Left Sidebar  -->
    <!-- Page wrapper  -->
    <div class="page-wrapper">
        <!-- 锐高软件 -->
        <%@ include file="../common/ruigao.jsp" %>


        <!-- 内容 -->
        <div class="container-fluid">
            <!-- Start Page Content -->
            <div class="row justify-content-center">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="card-content">
                                <!-- Left sidebar -->
                                <div class="inbox-leftbar">

                                    <a href="${pageContext.request.contextPath}/applicationpag"
                                       class="btn btn-danger btn-block waves-effect waves-light">返回列表</a>
                                </div>
                                <!-- End Left sidebar -->
                                <div class="inbox-rightbar">
                                    <div role="toolbar" class="">
                                        <div class="btn-group">
                                            <button class="btn btn-light waves-effect" type="button">
                                                <i class="mdi mdi-archive font-18 vertical-middle"></i>
                                            </button>
                                            <button class="btn btn-light waves-effect" type="button">
                                                <i class="mdi mdi-alert-octagon font-18 vertical-middle"></i>
                                            </button>
                                            <button class="btn btn-light waves-effect" type="button">
                                                <i class="mdi mdi-delete-variant font-18 vertical-middle"></i>
                                            </button>
                                        </div>

                                    </div>
                                </div>

                                <c:forEach items="${applists}" var="litmid">
                                    <div class="mt-4">
                                        <input type="hidden" name="status" id="statusshow"
                                               value="${litmid.applicationStatus}">

                                        <h5>标题：${litmid.applicationTitle }</h5>
                                        <hr/>
                                        <div class="media mb-4 mt-1">
                                            <img class="d-flex mr-3 rounded-circle thumb-sm"
                                                 src="${pageContext.request.contextPath}/images/users/avatar-2.jpg"
                                                 alt="Generic placeholder image">
                                            <div class="media-body">
                                                <span class="pull-right">时间: <fmt:formatDate type="both"
                                                                                             value="${litmid.applicationTime}"
                                                                                             pattern="yyyy-MM-dd HH:mm:ss"/></span>

                                                <c:forEach var="user" items="${UserList}">
                                                    <c:if test="${litmid.userId eq user.userId}">
                                                        <h6 class="m-0">申请人: ${user.userName}</h6>
                                                    </c:if>

                                                </c:forEach>


                                                <small class="text-muted">类型: ${litmid.applicationType }</small>
                                            </div>
                                        </div>

                                        <p>原因：${litmid.applicationReason }</p>

                                        <hr/>
                                    </div>

                                    <div class="media mb-4 mt-1 showjujue">
                                        <span class="pull-right show-jujue">拒绝原因：${litmid.applicationRefuse }</span>
                                    </div>
                                    <div class="media mb-4 mt-1">
                                        <c:forEach var="comps" items="${comp}">
                                            <c:if test="${litmid.companyId eq comps.companyId}">
                                                <span class="pull-right">公司：${comps.companyName }</span>

                                            </c:if>

                                        </c:forEach>
                                    </div>

                                    <c:if test="${competence ne 0 }">
                                        <div class="text-right">
                                            <div class="sweetalert m-t-15">
                                                <button class="btn btn-danger btn sweet-prompt">拒绝申请</button>
                                                <input type="hidden" name="opt" id="opt" value="">
                                                <input type="hidden" name="tid" id="tid"
                                                       value="${litmid.applicationId}">
                                                <button class="btn btn-success btn sweet-success">批准申请</button>
                                            </div>
                                        </div>
                                    </c:if>
                                </c:forEach>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- End PAge Content -->
    </div>
    <!-- End Container fluid  -->
</div>
</div>
<!-- footer -->
<%@ include file="../common/footer.jsp" %>
<!-- End footer -->
<%@ include file="../common/js.jsp" %>
<script type="text/javascript">
    $(function () {
        //判断当前登录的员工的权限
        var competence = ${competence};
        if (competence != -1) {
            //判断当前选中的申请是否已经批准
            var show = parseInt($("#statusshow").val());
            if (show == 2) {
                $(".text-right").hide();
                $(".showjujue").hide();

            } else if (show == 1) {
                $(".text-right").hide();
            } else if (show == 0) {
                $(".showjujue").hide();
            }

        }

        //点击拒绝按钮
        $(".sweet-prompt").click(function () {
            swal({
                    title: "拒绝原因",
                    type: "input",
                    showCancelButton: true,
                    closeOnConfirm: false,
                    animation: "slide-from-top",
                    inputPlaceholder: "请输入拒绝原因 ",
                    cancelButtonText: "取消",
                    confirmButtonText: "确定"
                },
                function (inputValue) {
                    if (inputValue === false) return false;
                    if (inputValue === "") {
                        swal.showInputError("您没有输入拒绝原因");
                        return false
                    }
                    //在这里获取到input的值
                    var inputvalue = inputValue;
                    $("#opt").val("applicationRefuse");
                    var applicationRefuse = $("#opt").val();
                    var tid = $("#tid").val();
                    $.ajax({
                        url: "applicationlist",
                        data: {"inputvalue": inputvalue, "opt": applicationRefuse, "tid": tid},
                        type: "GET",
                        dataType: "json",
                        success: function (data) {
                            if (data) {
                                swal({
                                        title: "操作成功!",
                                        type: 'success',
                                        text: "是否返回列表查看？",
                                        showCancelButton: true,
                                        closeOnConfirm: false,
                                        cancelButtonText: "取消",
                                        confirmButtonText: "确定"
                                    },
                                    function (inputValue) {
                                        if (inputValue === true) {
                                            location.href = "${pageContext.request.contextPath}/applicationpag";
                                        } else {
                                            return false;
                                        }
                                    });
                            }

                        }, error: function (data) {
                            swal({
                                title: '操作失败！',
                                type: 'error',
                                confirmButtonText: '确定',
                                closeOnConfirm: false
                            });
                        }
                    });
                });
        });

        //点击批准按钮
        $(".sweet-success").click(function () {
            swal({
                    title: "您确定要批准申请吗？",
                    animation: "slide-from-top",
                    showCancelButton: true,
                    closeOnConfirm: false,
                    cancelButtonText: "取消",
                    confirmButtonText: "确定"
                },
                function (inputValue) {
                    if (inputValue === false) {
                        return false;
                    } else {
                        $("#opt").val("applicationok");
                        var applicationRefuse = $("#opt").val();
                        var tid = $("#tid").val();
                        $.ajax({
                            url: "applicationlist",
                            data: {"opt": applicationRefuse, "tid": tid},
                            type: "GET",
                            dataType: "json",
                            success: function (data) {
                                if (data) {
                                    swal({
                                            title: "操作成功!",
                                            type: 'success',
                                            text: "是否返回列表查看？",
                                            showCancelButton: true,
                                            closeOnConfirm: false,
                                            cancelButtonText: "取消",
                                            confirmButtonText: "确定"
                                        },
                                        function (inputValue) {
                                            if (inputValue === true) {
                                                location.href = "${pageContext.request.contextPath}/applicationpag";
                                            } else {
                                                return false;
                                            }
                                        });
                                }
                            }, error: function (data) {
                                swal({
                                    title: '操作失败！',
                                    type: 'error',
                                    confirmButtonText: '确定',
                                    closeOnConfirm: false
                                });
                            }
                        });

                    }

                });
        });


    });

</script>


</body>

</html>